<?php

/** @var DatabaseModel $this */
/** @var int $t_success */

$isActiveSet = $this->query(
    "SELECT `value` from gx_configurations WHERE `key` = 'cronjobs/DeleteLogs/active';",
    true
);

$isThresholdSet = $this->query(
    "SELECT `value` from gx_configurations WHERE `key` = 'cronjobs/DeleteLogs/olderThan';",
    true
);

if ($isActiveSet->num_rows > 0) {
    $t_success &= $this->query(
        "UPDATE gx_configurations SET `value` = 'true' WHERE `key` = 'cronjobs/DeleteLogs/active';",
        true
    );
} else {
    $t_success &= $this->query(
        "INSERT INTO gx_configurations (`key`, `value`, `type`, `sort_order`) VALUES ('cronjobs/DeleteLogs/active', 'true', 'true', NULL)",
        true
    );
}

if ($isThresholdSet->num_rows > 0) {
    $t_success &= $this->query(
        "UPDATE gx_configurations SET `value` = '2' WHERE `key` = 'cronjobs/DeleteLogs/olderThan';",
        true
    );
} else {
    $t_success &= $this->query("INSERT INTO gx_configurations (`key`, `value`, `type`, `sort_order`) VALUES ('cronjobs/DeleteLogs/olderThan', '2', '2', NULL)",
        true
    );
}